package cn.org.spring.wechar.exception;

import cn.org.spring.wechar.bean.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

/**
 * @author： 谢辉
 * @date： 2021/5/20
 * @email: xieh_mail@163.com
 * @description： 集中处理所有controller异常
 * @modifiedBy：
 * @version: 1.0
 */
@Slf4j
@ControllerAdvice(basePackages = "cn.org.spring.wechar")
public class ExceptionControllerAdvice {

    /**
     * 响应json数据
     *
     * @param throwable
     * @return
     */
    @ResponseBody
    @ExceptionHandler(value = Exception.class)
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public Result handleException(Exception throwable) {
        log.error("错误异常{}", throwable);
        return Result.fail("发生未知错误，稍后在试~");
    }

}
